package com.ctl.util;

import com.aliyun.oss.ClientException;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.OSSException;
import com.aliyun.oss.model.PutObjectRequest;
import com.aliyun.oss.model.PutObjectResult;
import org.springframework.stereotype.Component;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;

@Component
public class OssUtils {
    private static String ACCESSKEYID="LTAI5t6VqBzDo8ekuP8aGGzn";
    private static String SECRET="Y29i6Y4iZOrGNU63shpmrFoncAyyKR";

    public static String upload(InputStream inputStream, String path, String fileName){
        String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
        OSS ossClient = new OSSClientBuilder().build(endpoint, ACCESSKEYID, SECRET);
        String bucketName = "bzkt-fore-api";
        String key = path + "/" + fileName;
        ossClient.putObject(bucketName, key, inputStream);
        ossClient.shutdown();
        return "https://" + bucketName + ".oss-cn-hangzhou.aliyuncs.com/" + key;
    }

}
